function getDaysUntilSalaryPayday(referenceDate = new Date()) {
    const today = new Date(referenceDate);
    today.setHours(0, 0, 0, 0);

    // 构造当前月的15号
    let payday = new Date(today.getFullYear(), today.getMonth(), 15);

    // 如果15号已过，切换到下个月
    if (today > payday) {
        payday = new Date(today.getFullYear(), today.getMonth() + 1, 15);
    }

    // 顺延到下一个工作日（如果是周六或周日）
    while (payday.getDay() === 6 || payday.getDay() === 0) {
        payday.setDate(payday.getDate() + 1);
    }
    // 计算天数差
    const msPerDay = 1000 * 60 * 60 * 24;
    const diffDays = Math.ceil((payday - today) / msPerDay);

    console.log(payday.toISOString())
    return {
        adjustedPayday: payday.toISOString().slice(0, 10),
        realAdjustedPayday: formatDateToBeijing(payday).slice(0, 10),
        daysUntilPayday: diffDays
    };
}
function formatDateToBeijing(dateObj) {
    if (!(dateObj instanceof Date)) {
        throw new Error("参数必须是 Date 类型");
    }

    // 将时间转换为 UTC+8
    const utc8Time = new Date(dateObj.getTime() + 8 * 60 * 60 * 1000);

    // 提取年月日时分秒
    const y = utc8Time.getUTCFullYear();
    const m = String(utc8Time.getUTCMonth() + 1).padStart(2, '0');
    const d = String(utc8Time.getUTCDate()).padStart(2, '0');
    const h = String(utc8Time.getUTCHours()).padStart(2, '0');
    const min = String(utc8Time.getUTCMinutes()).padStart(2, '0');
    const s = String(utc8Time.getUTCSeconds()).padStart(2, '0');

    return `${y}-${m}-${d} ${h}:${min}:${s}`;
}


// 示例调用
// 输出：2025-06-16 00:00:00

// 示例调用
const result = getDaysUntilSalaryPayday();
console.log(`发薪日：${result.adjustedPayday}(实际发薪日:${result.realAdjustedPayday})`);
console.log(`距离发薪水还有：${result.daysUntilPayday} 天`);
